```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MySQL可重复读隔离级别深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.75;
            color: #2d3748;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 700;
            color: #1a202c;
        }
        .hero {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .code-block {
            background: #1e293b;
            border-left: 4px solid #7c3aed;
        }
        .icon-circle {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .first-letter:first-letter {
            float: left;
            font-size: 4rem;
            line-height: 0.65;
            margin: 0.1em 0.2em 0 0;
            color: #4f46e5;
            font-weight: bold;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-4xl flex flex-col items-center text-center">
            <div class="icon-circle rounded-full flex items-center justify-center mb-6 shadow-xl">
                <i class="fas fa-database text-white text-2xl"></i>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-4">MySQL可重复读隔离级别</h1>
            <p class="text-xl md:text-2xl text-indigo-100 max-w-3xl mb-8">深入解析事务一致性的实现机制</p>
            <div class="w-full max-w-2xl bg-white bg-opacity-10 rounded-lg p-6 backdrop-blur-sm">
                <p class="text-indigo-50 text-lg">"可重复读（Repeatable Read）确保在一个事务内，多次读取相同数据时结果一致，不受其他事务提交的影响，这是MySQL默认的隔离级别。"</p>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-4xl px-4 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="first-letter text-gray-800 text-lg leading-relaxed">
                在数据库系统中，事务隔离级别是控制并发事务相互影响程度的重要机制。MySQL的InnoDB存储引擎默认采用可重复读（Repeatable Read）隔离级别，它通过多版本并发控制（MVCC）和锁机制等技术手段，在保证并发性能的同时确保事务内读取数据的一致性。本文将深入探讨这一隔离级别的实现原理和实际应用。
            </div>
        </section>

        <!-- MVCC Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 border-l-4 border-indigo-500 pl-4 flex items-center">
                <i class="fas fa-layer-group text-indigo-500 mr-3"></i>
                多版本并发控制（MVCC）
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card transition-all duration-300">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-3 text-indigo-600 flex items-center">
                            <i class="fas fa-copy mr-2"></i>
                            数据快照机制
                        </h3>
                        <p class="text-gray-700">每个事务开始时，系统会为其创建一个数据快照。事务内的所有读取操作都基于这个快照，确保在整个事务期间看到的数据视图保持一致，不受其他事务修改的影响。</p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden card transition-all duration-300">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-3 text-indigo-600 flex items-center">
                            <i class="fas fa-code-branch mr-2"></i>
                            版本控制与Undo Log
                        </h3>
                        <p class="text-gray-700">InnoDB通过数据行的版本号和Undo Log实现多版本控制。修改前的数据版本保存在Undo Log中，确保事务可以访问到特定时间点的数据状态。</p>
                    </div>
                </div>
            </div>

            <div class="mb-8">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800 flex items-center">
                    <i class="fas fa-terminal mr-2 text-indigo-500"></i>
                    示例代码
                </h3>
                <div class="code-block rounded-lg overflow-hidden">
                    <pre class="text-gray-200 p-4"><code>START TRANSACTION;
SELECT * FROM orders WHERE order_id = 1;
-- 其他事务在这个事务提交前对订单的修改
-- 不会影响当前事务的读取结果
COMMIT;</code></pre>
                </div>
            </div>

            <div class="bg-indigo-50 rounded-xl p-6 border border-indigo-100">
                <h4 class="font-semibold text-indigo-700 mb-3 flex items-center">
                    <i class="fas fa-lightbulb mr-2"></i>
                    技术细节
                </h4>
                <ul class="list-disc pl-5 text-gray-700 space-y-2">
                    <li>每个事务有一个唯一的事务ID，用于标识数据版本</li>
                    <li>数据行包含创建版本号和删除版本号字段</li>
                    <li>读取操作只查找创建版本号小于当前事务ID且删除版本号大于当前事务ID的数据</li>
                </ul>
            </div>
        </section>

        <!-- Lock Mechanism Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 border-l-4 border-indigo-500 pl-4 flex items-center">
                <i class="fas fa-lock text-indigo-500 mr-3"></i>
                锁机制
            </h2>
            
            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <div class="text-indigo-500 mb-3">
                        <i class="fas fa-grip-lines text-2xl"></i>
                    </div>
                    <h3 class="font-semibold text-lg mb-2">行级锁</h3>
                    <p class="text-gray-700 text-sm">事务修改数据时锁定特定行，防止并发修改</p>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <div class="text-indigo-500 mb-3">
                        <i class="fas fa-arrows-alt-h text-2xl"></i>
                    </div>
                    <h3 class="font-semibold text-lg mb-2">间隙锁</h3>
                    <p class="text-gray-700 text-sm">锁定索引记录之间的间隙，防止幻读</p>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <div class="text-indigo-500 mb-3">
                        <i class="fas fa-lock-open text-2xl"></i>
                    </div>
                    <h3 class="font-semibold text-lg mb-2">意向锁</h3>
                    <p class="text-gray-700 text-sm">表级锁，表示事务打算在表中的行上加锁</p>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-2xl font-semibold mb-4 text-gray-800">锁机制实现示例</h3>
                    <div class="code-block rounded-lg overflow-hidden">
                        <pre class="text-gray-200 p-4"><code>START TRANSACTION;
SELECT * FROM products 
WHERE price > 100 FOR UPDATE;
-- 锁定符合条件的行
-- 防止其他事务修改这些行
COMMIT;</code></pre>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-2xl font-semibold mb-4 text-gray-800">间隙锁示例</h3>
                    <div class="code-block rounded-lg overflow-hidden">
                        <pre class="text-gray-200 p-4"><code>START TRANSACTION;
SELECT * FROM employees 
WHERE department_id = 1;
-- 锁定department_id=1的范围
-- 防止其他事务插入新记录
COMMIT;</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Phantom Read Prevention -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 border-l-4 border-indigo-500 pl-4 flex items-center">
                <i class="fas fa-ghost text-indigo-500 mr-3"></i>
                防止幻读
            </h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card transition-all duration-300">
                <div class="p-6">
                    <div class="flex items-start">
                        <div class="flex-shrink-0 bg-indigo-100 p-3 rounded-lg mr-4">
                            <i class="fas fa-exclamation-triangle text-indigo-600 text-xl"></i>
                        </div>
                        <div>
                            <h3 class="text-xl font-semibold mb-2 text-gray-800">什么是幻读？</h3>
                            <p class="text-gray-700">幻读是指在同一事务中，连续执行两次相同的查询可能得到不同的结果集，因为其他事务在这期间插入了新的满足条件的记录。</p>
                        </div>
                    </div>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-2xl font-semibold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-shield-alt mr-2 text-indigo-500"></i>
                        InnoDB的解决方案
                    </h3>
                    <p class="text-gray-700 mb-4">InnoDB在可重复读隔离级别下通过间隙锁(Gap Lock)防止幻读。间隙锁锁定索引记录之间的间隙，阻止其他事务在查询范围内插入新记录。</p>
                    
                    <div class="bg-blue-50 rounded-lg p-4 border border-blue-100">
                        <h4 class="font-semibold text-blue-700 mb-2">间隙锁特点：</h4>
                        <ul class="list-disc pl-5 text-gray-700 space-y-1 text-sm">
                            <li>仅在可重复读隔离级别下有效</li>
                            <li>基于索引工作，无索引时会锁表</li>
                            <li>与行锁组合使用形成"next-key lock"</li>
                        </ul>
                    </div>
                </div>
                
                <div>
                    <div id="mermaid-diagram" class="bg-white p-4 rounded-xl shadow-sm">
                        <!-- Mermaid diagram will be rendered here -->
                    </div>
                </div>
            </div>
        </section>

        <!-- Comparison Section -->
        <section>
            <h2 class="text-3xl font-bold mb-6 border-l-4 border-indigo-500 pl-4">隔离级别对比</h2>
            
            <div class="overflow-x-auto">
                <table class="min-w-full bg-white rounded-lg overflow-hidden">
                    <thead class="bg-indigo-600 text-white">
                        <tr>
                            <th class="py-3 px-4 text-left">隔离级别</th>
                            <th class="py-3 px-4 text-left">脏读</th>
                            <th class="py-3 px-4 text-left">不可重复读</th>
                            <th class="py-3 px-4 text-left">幻读</th>
                            <th class="py-3 px-4 text-left">实现机制</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200">
                        <tr class="hover:bg-gray-50">
                            <td class="py-3 px-4 font-medium">读未提交</td>
                            <td class="py-3 px-4 text-red-500"><i class="fas fa-times"></i></td>
                            <td class="py-3 px-4 text-red-500"><i class="fas fa-times"></i></td>
                            <td class="py-3 px-4 text-red-500"><i class="fas fa-times"></i></td>
                            <td class="py-3 px-4 text-sm">无锁/读不加锁</td>
                        </tr>
                        <tr class="hover:bg-gray-50 bg-gray-50">
                            <td class="py-3 px-4 font-medium">读已提交</td>
                            <td class="py-3 px-4 text-green-500"><i class="fas fa-check"></i></td>
                            <td class="py-3 px-4 text-red-500"><i class="fas fa-times"></i></td>
                            <td class="py-3 px-4 text-red-500"><i class="fas fa-times"></i></td>
                            <td class="py-3 px-4 text-sm">MVCC(每语句快照)</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="py-3 px-4 font-medium text-indigo-600">可重复读</td>
                            <td class="py-3 px-4 text-green-500"><i class="fas fa-check"></i></td>
                            <td class="py-3 px-4 text-green-500"><i class="fas fa-check"></i></td>
                            <td class="py-3 px-4 text-green-500"><i class="fas fa-check"></i></td>
                            <td class="py-3 px-4 text-sm">MVCC + 间隙锁</td>
                        </tr>
                        <tr class="hover:bg-gray-50 bg-gray-50">
                            <td class="py-3 px-4 font-medium">串行化</td>
                            <td class="py-3 px-4 text-green-500"><i class="fas fa-check"></i></td>
                            <td class="py-3 px-4 text-green-500"><i class="fas fa-check"></i></td>
                            <td class="py-3 px-4 text-green-500"><i class="fas fa-check"></i></td>
                            <td class="py-3 px-4 text-sm">完全串行执行</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </section>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true
            }
        });
        
        document.addEventListener('DOMContentLoaded', function() {
            const diagram = `graph TD
                A[事务A开始] --> B[查询范围10-20]
                B --> C[获取间隙锁10-20]
                D[事务B尝试插入15] --> E{是否在锁定间隙?}
                E -->|是| F[阻塞等待]
                E -->|否| G[执行插入]
                C --> H[事务A再次查询10-20]
                H --> I[结果集一致]`;
            
            document.getElementById('mermaid-diagram').innerHTML = `<div class="mermaid">${diagram}</div>`;
        });
    </script>
</body>
</html>
```